/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.bashsoft.nero.nameparser;

import java.io.IOException;
import java.util.List;
import org.jdom.*;
import org.jdom.output.*;

/**
 *
 * @author nero
 */
public class XmlHelper {
    
    public static void savePlayers(List<Player> players, String fileName) throws IOException {
        Document document = new Document();
        Element rootElement = new Element("Players");        
        for (Player player : players) {
            if ((player.name == null) || (player.name == "")) continue;
            if ((player.nation == null) || (player.nation == "")) continue;
            Element playerElement = new Element("Player");            
            playerElement.setAttribute("Name", player.name);
            playerElement.setAttribute("Nation", player.nation);
            rootElement.addContent(playerElement);
        }
        document.setRootElement(rootElement);
        XMLOutputter outputter = new XMLOutputter();
        java.io.FileWriter writer = new java.io.FileWriter(fileName);
        try {            
            outputter.output(document, writer);
        }
        finally {
            writer.close();
        }
    }
    
}
